//
//  TestTableView.m
//  GameBaby
//
//  Created by keyZhang on 13-12-29.
//  Copyright (c) 2013年 keyZhang. All rights reserved.
//

#import "TestTableView.h"
#import "TestTableViewCell.h"
#import "GameCenterViewController.h"

@implementation TestTableView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}


- (void)awakeFromNib
{
    [super awakeFromNib];
    self.rowHeight = 80;
    self.separatorStyle = UITableViewCellSeparatorStyleNone;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

#pragma mark -UITableViewDelegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.dataList.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.dataList[section] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"TestCell";
    TestTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"TestTableViewCell" owner:self options:nil] lastObject];
    }
    
    cell.model = [self.dataList[indexPath.section] objectAtIndex:indexPath.row];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 30.0;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *sHeadView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)];
    sHeadView.backgroundColor = [UIColor whiteColor];
    UIImageView *dateImgView = [[UIImageView alloc] initWithFrame:CGRectMake(6, 5, 20, 19)];
    dateImgView.image = [UIImage imageNamed:@"m_05X2.png"];
    [sHeadView addSubview:dateImgView];
    
    UIImageView *detailDateImgView = [[UIImageView alloc] initWithFrame:CGRectMake(26, 8, 53, 16)];
    detailDateImgView.image = [UIImage imageNamed:@"m_08X2.png"];
    
    UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(13, 0, 40, 16)];
//    timeLabel.textAlignment = UITextAlignmentCenter;
    timeLabel.textColor = [UIColor whiteColor];
    timeLabel.backgroundColor = [UIColor clearColor];
    timeLabel.font = [UIFont boldSystemFontOfSize:8];
    timeLabel.text = self.dateDataList[section];
    
    [detailDateImgView addSubview:timeLabel];
    
    [sHeadView addSubview:detailDateImgView];
    
    
    
    UIImageView *buttomLineImg = [[UIImageView alloc] initWithFrame:CGRectMake(15, 23, 2, 20)];
    buttomLineImg.image = [UIImage imageNamed:@"m_17X2.png"];
    [sHeadView addSubview:buttomLineImg];
    
    if (section != 0) {
        UIImageView *topLineImg = [[UIImageView alloc] initWithFrame:CGRectMake(15, 0, 2, 5)];
        topLineImg.image = [UIImage imageNamed:@"m_17X2.png"];
        [sHeadView addSubview:topLineImg];
    }
    return sHeadView;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    GameCenterViewController *gameCenterVC = [[GameCenterViewController alloc] init];
    gameCenterVC.gameXqUrl = [(TestCellModel *)[self.dataList[indexPath.section] objectAtIndex:indexPath.row] url];
    [self.viewController.navigationController pushViewController:gameCenterVC animated:YES];
}


- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView *)view
{
    [super egoRefreshTableHeaderDidTriggerRefresh:view];
    if (self.finishBlock != nil) {
        
    }
}

@end
